package org.surthi.app.school.bean;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table( name="SECTION" )
public class Section implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2518624142564567674L;

	/**
	 * Represents primaryKey/unique number for the section
	 */
	private Integer sectionId;
	
	/**
	 * Represents name of the section
	 */
	private String	name;
	
	/**
	 *
	 */
	private Set<StandardClass> classes;
		
	@Id
	@GeneratedValue(generator="increment")
	@GenericGenerator(name="increment", strategy="increment")
	@Column(name="SECT_ID")
	public Integer getSectionId() {
		return sectionId;
	}

	public void setSectionId(Integer sectionId) {
		this.sectionId = sectionId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@ManyToMany(cascade= {CascadeType.PERSIST, CascadeType.MERGE}, mappedBy="sections", targetEntity=StandardClass.class)
	public Set<StandardClass> getClasses() {
		return classes;
	}

	public void setClasses(Set<StandardClass> classes){
		this.classes = classes;
	}
	public void addClassToSection(StandardClass standardClass) {
		if (this.classes == null ){
			this.classes = new HashSet<StandardClass>();
		}
		this.classes.add(standardClass);
	}
}
